package com.authsphere.logging.common.utils;

import com.authsphere.logging.common.config.GenericGlobalConfig;
import com.authsphere.logging.common.config.LogThreadPoolConfig;

import java.util.Map;
import java.util.Optional;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/5 20:38
 **/
public class LogCollectConfigUtils {
    private static GenericGlobalConfig genericGlobalConfig;

    private static LogThreadPoolConfig logThreadPoolConfig;

    private static final GenericGlobalConfig DEFAULT_GLOBAL_LOG_CONFIG =
            new GenericGlobalConfig();

    private static final LogThreadPoolConfig DEFAULT_LOG_THREAD_POOL_CONFIG =
            new LogThreadPoolConfig();

    private LogCollectConfigUtils() {
    }

    /**
     * get global log config.
     *
     * @return global log config
     */
    public static GenericGlobalConfig getGenericGlobalConfig() {
        return Optional.ofNullable(genericGlobalConfig).orElse(DEFAULT_GLOBAL_LOG_CONFIG);
    }

    /**
     * set generic global config.
     *
     * @param config global config
     */
    public static void setGenericGlobalConfig(final GenericGlobalConfig config) {
        genericGlobalConfig = config;
    }

    /**
     * get log thread pool config.
     *
     * @return log thread pool config
     */
    public static LogThreadPoolConfig getLogThreadPoolConfig() {
        return Optional.ofNullable(logThreadPoolConfig).orElse(DEFAULT_LOG_THREAD_POOL_CONFIG);
    }

    /**
     * set log thread pool config.
     *
     * @param config log thread pool config
     */
    public static void setLogThreadPoolConfig(final LogThreadPoolConfig config) {
        logThreadPoolConfig = config;
    }

    /**
     * get message queue topic.
     *
     * @param moduleType       moduleType
     * @param apiTopicMap api topic map
     * @return topic
     */
    public static String getTopic(final String moduleType, final Map<String, String> apiTopicMap) {
        return apiTopicMap.getOrDefault(moduleType, "");
    }
}
